import { useUserKey } from "@/store/user";
import router from "@/router";

export const relogin = (before?: () => void, after?: () => void) => {
  const userStore = useUserKey();
  before && before();
  localStorage.removeItem("token");
  // 清除动态路由
  userStore.routes.forEach((item) => {
    router.removeRoute(item.name);
  });
  // 清除全局pinia
  // 一定要注意pinia是分多个仓库的，如果有多个仓库一定要把每个都清除
  userStore.menus = [];
  userStore.username = "";

  // 跳转登录页
  router.push("/login");
  after && after();
};
